package com.example.onlinemonitoring.serviceImpl;

import com.example.onlinemonitoring.model.Jddlsensor;
import com.example.onlinemonitoring.model.Jddlhistory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.onlinemonitoring.Util.tem.SensorAbstractBaseService;
import com.example.onlinemonitoring.dao.JddlhistoryMapper;
import com.example.onlinemonitoring.dao.JddlsensorMapper;
import com.example.onlinemonitoring.service.JddlsensorService;

import tk.mybatis.mapper.entity.Example;

import com.example.onlinemonitoring.model.common.MyResult;
import com.example.onlinemonitoring.model.common.chartres;
import com.example.onlinemonitoring.model.common.dcurrentaddrconfig;
import com.example.onlinemonitoring.Util.HexUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import com.example.onlinemonitoring.model.common.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.onlinemonitoring.model.common.dcurrentaddrconfig;
import org.springframework.transaction.annotation.Transactional;

/**
* @description Jddlsensor接口实现
* @author  generator
* @since  2023-11-01 10:59:09
*/
@Service("jddlServiceImpl")
public class JddlsensorServiceImpl extends SensorAbstractBaseService<Jddlsensor, Jddlhistory> implements JddlsensorService {
     //这里需要重写getDt方法,用来处理图表数据
    //public String[] getDt(List<Jddlhistory> list,String[] dt,chartres cts,float[][] sres,SimpleDateFormat sdf,SimpleDateFormat csdf,SimpleDateFormat sdf2){return null;}
    @Autowired
    private JddlsensorMapper jddlsensormapper;
    @Autowired
    private JddlhistoryMapper jddlhistorymapper;
        public MyResult<dcurrentaddrconfig> selectaddr(Jddlsensor record) {
        MyResult<dcurrentaddrconfig> result = new MyResult<dcurrentaddrconfig>();
        List<dcurrentaddrconfig> list = jddlsensormapper.selectaddr(record); 
        if (list.size() != 0) {
            result.setCode(0);
            result.setMsg("success");
            result.setCount(list!=null&&!list.isEmpty()?list.size():0);
            result.setData(list);
        } else {
            result.setCode(1);
            result.setMsg("数据为空");
        }
        return result;
    }

    @Transactional
    public MyResult<Integer> Updatelastdcurrentaddr(dcurrentaddrconfig ptconfig, Integer stationid, Integer devicegroup) {
        Example example = new Example(Jddlsensor.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", stationid);
        criteria.andEqualTo("devicegroup", devicegroup);
        jddlsensormapper.setlastdcurrentaddr(stationid,devicegroup,ptconfig.getlastdcurrentaddr());
        if (ptconfig.getDlhlmin()!= 0 && ptconfig.getDlhlmax()!= 0) {
            Jddlsensor record = new Jddlsensor();
            record.setLastdcurrentaddr(ptconfig.getlastdcurrentaddr());
            criteria.andGreaterThanOrEqualTo("deviceaddr", ptconfig.getDlhlmin());
            criteria.andLessThanOrEqualTo("deviceaddr", ptconfig.getDlhlmax());
            updateByExampleSelective(record, example);
        }
        return new MyResult<Integer>(true);
    }

    public List<Jddlsensor> getlastdcurrentaddrModel(Jddlsensor alarm) {
        Example example = new Example(Jddlsensor.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", alarm.getStationid());
        criteria.andEqualTo("devicegroup", alarm.getDevicegroup());
        criteria.andEqualTo("lastdcurrentaddr", alarm.getLastdcurrentaddr());
        return jddlsensormapper.selectByExample(example);
    }
}
